home *** CD-ROM | disk | FTP | other *** search
/ Programming in Microsoft Windows with C# / Programacion en Microsoft Windows con C#.iso / Original Code / Taming the Mouse / MouseWeb / MouseWeb.cs next >
Encoding:
Text File  |  2001-01-15  |  2.2 KB  |  61 lines

  1. //---------------------------------------
  2. // MouseWeb.cs ⌐ 2001 by Charles Petzold
  3. //---------------------------------------
  4. using System;
  5. using System.Drawing;
  6. using System.Windows.Forms;
  7.  
  8. class MouseWeb: Form
  9. {
  10.      Point ptMouse = Point.Empty;
  11.  
  12.      public static void Main()
  13.      {
  14.           Application.Run(new MouseWeb());
  15.      }
  16.      public MouseWeb()
  17.      {
  18.           Text = "Mouse Web";
  19.           BackColor = SystemColors.Window;
  20.           ForeColor = SystemColors.WindowText;
  21.           ResizeRedraw = true;
  22.      }
  23.      protected override void OnMouseMove(MouseEventArgs mea)
  24.      {
  25.           Graphics grfx = CreateGraphics();
  26.  
  27.           DrawWeb(grfx, BackColor, ptMouse);
  28.           ptMouse = new Point(mea.X, mea.Y);
  29.           DrawWeb(grfx, ForeColor, ptMouse);
  30.  
  31.           grfx.Dispose();
  32.      }
  33.      protected override void OnPaint(PaintEventArgs pea)
  34.      {
  35.           DrawWeb(pea.Graphics, ForeColor, ptMouse);
  36.      }
  37.      void DrawWeb(Graphics grfx, Color clr, Point pt)
  38.      {
  39.           int cx  = ClientSize.Width;
  40.           int cy  = ClientSize.Height;
  41.           Pen pen = new Pen(clr);
  42.  
  43.           grfx.DrawLine(pen, pt, new Point(         0,          0));
  44.           grfx.DrawLine(pen, pt, new Point(    cx / 4,          0));
  45.           grfx.DrawLine(pen, pt, new Point(    cx / 2,          0));
  46.           grfx.DrawLine(pen, pt, new Point(3 * cx / 4,          0));
  47.           grfx.DrawLine(pen, pt, new Point(    cx    ,          0));
  48.           grfx.DrawLine(pen, pt, new Point(    cx    ,     cy / 4));
  49.           grfx.DrawLine(pen, pt, new Point(    cx    ,     cy / 2));
  50.           grfx.DrawLine(pen, pt, new Point(    cx    , 3 * cy / 4));
  51.           grfx.DrawLine(pen, pt, new Point(    cx    ,     cy    ));
  52.           grfx.DrawLine(pen, pt, new Point(3 * cx / 4,     cy    ));
  53.           grfx.DrawLine(pen, pt, new Point(    cx / 2,     cy    ));
  54.           grfx.DrawLine(pen, pt, new Point(    cx / 4,     cy    ));
  55.           grfx.DrawLine(pen, pt, new Point(         0,     cy    ));
  56.           grfx.DrawLine(pen, pt, new Point(         0,     cy / 4));
  57.           grfx.DrawLine(pen, pt, new Point(         0,     cy / 2));
  58.           grfx.DrawLine(pen, pt, new Point(         0, 3 * cy / 4));
  59.      }
  60. }
  61.